package com.bdyc.service.springImpl;

import org.springframework.stereotype.Service;

import com.bdyc.service.spring.FastWriteInfoService;
@Service("fastWriteInfoService")
public class FastWriteInfoServiceImpl implements FastWriteInfoService {
//	
//	@Autowired(required=true)
//	@Qualifier("fastWriteInfoMapper")
//	private FastWriteInfoMapper fastWriteInfoMapper;
//	
//	//操作快写mapper
//	@Autowired(required=true)
//	@Qualifier("orderInfoMapper")
//	private OrderInfoMapper orderInfoMapper;
//	@Autowired(required=true)
//	@Qualifier("orderWriteRelMapper")
//	private OrderWriteRelMapper orderWriteRelMapper;
//	@Autowired(required=true)
//	@Qualifier("userOrderRelMapper")
//	private UserOrderRelMapper userOrderRelMapper;
//	//操作类别mapper
//	@Autowired(required=true)
//	@Qualifier("cateKeyRelMapper")
//	private CateKeyRelMapper cateKeyRelMapper;
//	@Autowired(required=true)
//	@Qualifier("writeCateRelMapper")
//	private WriteCateRelMapper writeCateRelMapper;
//	
//	//添加快写任务方法 写入6张表
//	public void addFastWtireInfo(FastWriteInfo fastWriteInfo,Integer userId) {
//		OrderInfo orderInfo = new OrderInfo();
//		UserOrderRel userOrderRel = new UserOrderRel();
//		OrderWriteRel orderWriteRel = new OrderWriteRel();
//		//1插入快写表
//		fastWriteInfoMapper.insert(fastWriteInfo);
//		//封装orderInfo
//		orderInfo.setCreateTime(MyDateFormat.getTime());//添加创建时间
//		orderInfo.setName(fastWriteInfo.getName());//设置任务名称
//		orderInfo.setFlag(AppConstant.TASKWRITE);//设置任务种类
//		orderInfo.setNum(BusinessNumber.getOrderNo());//设置任务号
//		orderInfo.setPrice(fastWriteInfo.getPrice());//设置价格
//		orderInfo.setStatus(AppConstant.TASKFLAGONE);//设置任务状态
//		//2插入任务表
//		orderInfoMapper.insert(orderInfo);
//		//3插入userOrderRel表
//		userOrderRel.setOid(orderInfo.getId());
//		userOrderRel.setUid(userId);
//		userOrderRelMapper.insert(userOrderRel);
//		//4插入orderWriteRel表
//		orderWriteRel.setOid(orderInfo.getId());
//		orderWriteRel.setWid(fastWriteInfo.getId());
//		orderWriteRelMapper.insert(orderWriteRel);
//		//5.6插入WriteCateRel表和cateKeyRel表
//		String degree = fastWriteInfo.getDegree();
//		String [] degreeArr = degree.split(",");
//		for(int i=0;i<degreeArr.length;i++){
//			WriteCateRel writeCateRel = new WriteCateRel();
//			writeCateRel.setWid(fastWriteInfo.getId());
//			writeCateRel.setCid(Integer.valueOf(degreeArr[i]));
//			writeCateRelMapper.insert(writeCateRel);
//			/**如果数据库初始化后 插入WriteCateRel表和cateKeyRel表将无法匹配*/
//			if(degreeArr[i].equals("1")){
//				CateKeyRel cateKeyRel = new CateKeyRel();
//				cateKeyRel.setCid(1);
//				cateKeyRel.setWid(fastWriteInfo.getId());
//				cateKeyRel.setKid(Integer.valueOf(fastWriteInfo.getKeyword()));
//				cateKeyRelMapper.insert(cateKeyRel);
//			}
//		}
//	}
//	//修快写任务方法
//	// 1.先删除WriteCateRel表和cateKeyRel表的记录数据
//	// 2.再次把新记录添加进来
//	// 3.更新orderInfo表相应更改的字段(先查询出来)
//	public void updateFastWriteInfo(FastWriteInfo fastWriteInfo) {
//		//1
//		//删除writeCateRel表 根据wid
//		writeCateRelMapper.deleteByWId(fastWriteInfo.getId());
//		//删除cateKeyRel表 根据wid
//		cateKeyRelMapper.deleteByWId(fastWriteInfo.getId());
//		//2
//		String degree = fastWriteInfo.getDegree();
//		String [] degreeArr = degree.split(",");
//		for(int i=0;i<degreeArr.length;i++){
//			WriteCateRel writeCateRel = new WriteCateRel();
//			writeCateRel.setWid(fastWriteInfo.getId());
//			writeCateRel.setCid(Integer.valueOf(degreeArr[i]));
//			writeCateRelMapper.insert(writeCateRel);
//			/**如果数据库初始化后 插入WriteCateRel表和cateKeyRel表将无法匹配*/
//			if(degreeArr[i].equals("1")){
//				CateKeyRel cateKeyRel = new CateKeyRel();
//				cateKeyRel.setCid(1);
//				cateKeyRel.setWid(fastWriteInfo.getId());
//				cateKeyRel.setKid(Integer.valueOf(fastWriteInfo.getKeyword()));
//				cateKeyRelMapper.insert(cateKeyRel);
//			}
//		}
//		//3
//		OrderInfo updateOrderInfo = orderInfoMapper.selectOrderInfoByWId(fastWriteInfo.getId());
//		//任务编号已经固定 不能更改
//		updateOrderInfo.setCreateTime(MyDateFormat.getTime());//添加创建时间
//		updateOrderInfo.setName(fastWriteInfo.getName());//设置任务名称
//		updateOrderInfo.setFlag(AppConstant.TASKWRITE);//设置任务种类
//		updateOrderInfo.setPrice(fastWriteInfo.getPrice());//设置价格
//		updateOrderInfo.setStatus(AppConstant.TASKFLAGONE);//设置任务状态
//		orderInfoMapper.updateByPrimaryKey(updateOrderInfo);
//		fastWriteInfoMapper.updateByPrimaryKey(fastWriteInfo);
//	}
//	//删除快写任务方法 删除6张表
//	public void delFastWriteInfo(Integer id) {
//		//1删除order表 
//		orderInfoMapper.deleteById(id);
//		//2删除fastwrite表 根据oid查询wid
//		Integer wid = orderInfoMapper.selectWidByOId(id);
//		fastWriteInfoMapper.deleteByPrimaryKey(wid);
//		//3删除orderWriteRel表 根据oid
//		orderWriteRelMapper.deleteByWId(wid);
//		//4删除userOrderRel表 根据oId
//		userOrderRelMapper.deleteByOId(id);
//		//5删除writeCateRel表 根据wid
//		writeCateRelMapper.deleteByWId(wid);
//		//6删除cateKeyRel表 根据wid
//		cateKeyRelMapper.deleteByWId(wid);
//		
//	}
//	//查询快写方法
//	public FastWriteInfo findFastWriteInfoByOId(Integer OId) {
//		//根据Oid 在orderWriteRel查询fastwriteInfo Id
//		Integer id = orderWriteRelMapper.selectWIdByOid(OId);
//		//TODO keyword字段值
//		return fastWriteInfoMapper.selectByPrimaryKey(id);
//	}
}
